<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* Start of file user.php */
/* Location: ./member/controllers/user.php */
class User extends CI_Controller {
	
    /* constructor*/
	function __construct(){
		parent::__construct(); /* construct Stories user controller */
        session_start();
		$this->load->model('members');
    }
	
	/*link to member/user/register*/
	function register(){
		$this->ws->set('title',lang('sign_up')); /*Title Page From ws-include/language/region/global_lang*/
		$this->ws->set('javascript',array('js/jquery.min.js','js/jquery.cookie.min.js','js/facebox.1.3.min.js','js/wattpad.js','js/jquery-ui-1.8.16.custom.min.js')); /* Load Javascript*/
		$this->ws->set_theme('default');/*Set theme to default theme ws-themes/default*/
		$this->ws->set_layout('single');/*Set layout to default/single  ws-themes/default/single.php*/
		$this->ws->view('register');/*Set views home/views/register.php*/
	}
	
	/* register function*/
	function do_register(){
		$this->load->library('form_validation');
		$this->form_validation->set_rules('mtb_username','Choose a username','required|min_length[6]|max_length[20]|callback_do_checkUsername');
		$this->form_validation->set_rules('mtb_email','Enter your email address','required|valid_email|min_length[2]|max_length[50]|callback_do_checkEmail');
		$this->form_validation->set_rules('birthdate','Please enter mm-dd-yyyy','required');
		$this->form_validation->set_rules('mtb_terms','Please check the Agreement','required');
		if ($this->form_validation->run() == FALSE):
			$this->session->set_flashdata('validation_errors',validation_errors());
			redirect('member/user/register',301);
		else:
			$this->load->view('formsuccess');
		endif;
		$this->register();
	}
	
	/* function check username*/
	function do_checkUsername(){
		if(COUNT($this->members->getMemberData($this->input->post('mtb_username')))>0):
			$this->form_validation->set_message('do_checkUsername','That username is already taken.');
			return FALSE;
		else:
			return TRUE;
		endif;
	}

	/* function check email*/
	function do_checkEmail(){
		if(COUNT($this->members->getMemberData('',$this->input->post('mtb_email')))>0):
			$this->form_validation->set_message('do_checkEmail','That email address is already registered.');
			return FALSE;
		else:
			return TRUE;
		endif;
	}
	
	/*function do_checkDate*/
	function do_checkDate($date){
		//$ddmmyyy='(0[1-9]|[12][0-9]|3[01])[- -.](0[1-9]|1[012])[- -.](19|20)[0-9]{2}';
		$mmddyyyy='(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)[0-9]{2}';
	   if(preg_match("$mmddyyyy",$this->input->post('birthdate'))) {
		 return TRUE;
	   } else {
		 $this->form_validation->set_message('do_checkDate','Please enter mm-dd-yyyy');
		 return FALSE;
	   }
	}  
    
    /*link to member/user/login*/
	function login(){
		$this->ws->set('title',lang('login')); /*Title Page From ws-include/language/region/global_lang*/
		$this->ws->set_theme('default');/*Set theme to default theme ws-themes/default*/
		$this->ws->set_layout('single');/*Set layout to default/single  ws-themes/default/single.php*/
		$this->ws->view('login');/*Set views home/views/login.php*/
	}
    
    /* process login*/ 
    function do_login(){
        $user = array('user_id'=>'1','user_name'=>'repotman'); /* user_id and user_name session*/
        is_register($user); /* to function is_register to insert session userdata*/
        redirect('home/user/logged',301); /*redirect to myprofile , member/user/myprofile*/
    }
    
    /* process logout*/ 
    function do_logout(){
        is_logged_out();
        redirect('/',301);
    }
    
    /* link to member profile ,member/user/profile/name of profile*/
    function profile($user){
        $this->ws->set('title',user_auth('user_name')); /*Title Page From session user*/
        $this->ws->set('right_module',array('toggle','fans-gallery','recent-votes')); /* Load Right Module Side Jobs*/
		$this->ws->set_theme('default');/*Set theme to default theme ws-themes/default*/
		$this->ws->set_layout('index');/*Set layout to default/index  ws-themes/default/index.php*/
		$this->ws->view('profile');/*Set views messages/views/profile.php*/
    }
    
    /* link to member myprofile and setting ,member/user/myprofile/*/
    function myprofile(){
        $this->ws->set('title',lang('account_setting')); /*Title Page From ws-include/language/region/global_lang*/
        $this->ws->set('right_module',array('side-profile')); /* Load Right Module Side Jobs*/
		$this->ws->set_theme('default');/*Set theme to default theme ws-themes/default*/
		$this->ws->set_layout('index');/*Set layout to default/index  ws-themes/default/index.php*/
		$this->ws->view('myprofile');/*Set views messages/views/profile.php*/
    }
    
    /* link to member find friend  ,member/user/find_friend/*/
    function find_friend(){
        $this->ws->set('title',lang('find_friend')); /*Title Page From ws-include/language/region/global_lang*/
		$this->ws->set_theme('default');/*Set theme to default theme ws-themes/default*/
		$this->ws->set_layout('index');/*Set layout to default/index  ws-themes/default/index.php*/
		$this->ws->view('find-friends');/*Set views messages/views/find-friends.php*/
    }
    
    /* link to member list user  ,member/user/list/*/
    function listing($user){
        $this->ws->set('title',$user); /*Title Page From ws-include/language/region/global_lang*/
		$this->ws->set('right_module',array('member-popular','member-active','member-recent','member-newest')); /* Load Right Module Side Jobs*/
        $this->ws->set_theme('default');/*Set theme to default theme ws-themes/default*/
		$this->ws->set_layout('index');/*Set layout to default/index  ws-themes/default/index.php*/
		$this->ws->view('list');/*Set views messages/views/find-friends.php*/
    }
    
    /* link to member search*/
    function search($user=''){
        $this->ws->set('title',lang('search')); /*Title Page From ws-include/language/region/global_lang*/
		$this->ws->set('right_module',array('member-popular','member-active','member-recent','member-newest')); /* Load Right Module Side Jobs*/
        $this->ws->set_theme('default');/*Set theme to default theme ws-themes/default*/
		$this->ws->set_layout('index');/*Set layout to default/index  ws-themes/default/index.php*/
		$this->ws->view('search');/*Set views messages/views/find-friends.php*/    
    }    
        	
}
/* End of file user.php */
/* Location: ./member/controllers/user.php*/